cmake_minimum_required(VERSION 3.15)
project(gateway_beast_http LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

find_package(Boost 1.71 REQUIRED COMPONENTS system thread)
find_package(OpenSSL)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBJWT REQUIRED libjwt)

add_library(gateway_beast_http_core
    src/http_server.cpp
    src/router.cpp
    src/request_adapter.cpp
    src/response_adapter.cpp
    src/offload.cpp
)

target_include_directories(gateway_beast_http_core
    PUBLIC
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${CMAKE_SOURCE_DIR}
        ${LIBJWT_INCLUDE_DIRS}
)

target_link_libraries(gateway_beast_http_core
    PUBLIC
        Boost::system
        Boost::thread
        OpenSSL::Crypto
        ${LIBJWT_LIBRARIES}
        service_bus_v2
        service_registry
        grpc_client
        grpc_client_pool
        database
        config
        logger
        nlohmann_json::nlohmann_json
)

target_compile_options(gateway_beast_http_core PRIVATE ${LIBJWT_CFLAGS_OTHER})

add_executable(gateway_beast_http
    src/main.cpp
)

target_include_directories(gateway_beast_http
    PRIVATE
        ${CMAKE_CURRENT_SOURCE_DIR}/include
        ${CMAKE_SOURCE_DIR}
)

target_link_libraries(gateway_beast_http
    PRIVATE
        gateway_beast_http_core
)

install(TARGETS gateway_beast_http RUNTIME DESTINATION bin)
